<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\User;

class RegisterController extends Controller
{
    //
    /*
        显示注册页面
    */
      public function index(){
      	return view('register/index');
    	
    }
    /*
      注册功能实现
    */

      public function register(){
      		
      		//validate
      		$this->validate(request(),[

      			'name'=>'required|min:2|unique:users,name',
      			'email'=>'required|unique:users,email|email',
      			'password'=>'required|min:3|confirmed'

      		]);

      		//logic
          $name=request('name');
          $email=request('email');
          $password=bcrypt(request('password'));
           $user=User::create(compact('name','email','password'));

      		//view
           return  redirect('/login');
     }	
}
